Skip to main content

Copy paste detector

Why should you care about duplicate code blocks?

Assuming duplicated blocks of code are supposed to do the same thing, any refactoring, even simple, must be duplicated too which is unrewarding grunt work, and puts pressure on the developer to find every place in which to perform the refactoring. Automated tools can help with that to some extent.

However, failure to keep the code in sync may mean automated tools will no longer recognise these blocks as duplicates. This means the task of finding duplicates to keep them in sync when doing subsequent refactorings can no longer be entrusted to an automated tool adding more burden on the maintainer. Segments of code initially supposed to do the same thing may grow apart undetected upon further refactoring.

Now, if the code may never change in the future, then this is not a problem.

Otherwise, the most viable solution is to not duplicate. If the duplicates are already there, then they should be refactored out. We thus advise developers to remove duplicates, not to help keep duplicates in sync.